package com.gxc.browser.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author GongXincheng
 * @since 2019-10-15 14:28
 */
@Slf4j
@Component
public class MyUserDetailServiceImpl implements UserDetailsService {

    @Resource
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.info("登录用户名为：{}", username);
        String encodePwd = passwordEncoder.encode("123qwe");
        log.info("加密后密码为：{}", encodePwd);
        return new User(username, encodePwd, AuthorityUtils.commaSeparatedStringToAuthorityList("admin,gxc"));
    }
}
